﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Core.CMS.Providers;
using Core.Configuration;
using System.Configuration;
using System.Configuration.Provider;
using System.Web.Configuration;
using Core.DMS.Providers;

namespace Core
{
    internal static class AppFunctions
    {
        static ContentProvider contentProvider;
        static DocumentProvider docProvider;
        public static ContentProvider Content { get { return contentProvider; } }
        public static DocumentProvider Documents { get { return docProvider; } }

        static AppFunctions()
        {
            // Load registered providers and provide a reference to the default providers
            ProviderCollection _providers = new ProviderCollection();

            try
            {
                // first content
                ConfigSection contentSection = (ConfigSection)ConfigurationManager.GetSection("AppFunctions/Content");
                ProvidersHelper.InstantiateProviders(contentSection.Providers, _providers, typeof(ContentProvider));
                contentProvider = (ContentProvider)_providers[contentSection.DefaultProvider];
            }
            catch { }

            try
            {
                // then documents
                ConfigSection docsection = (ConfigSection)ConfigurationManager.GetSection("AppFunctions/Documents");
                ProvidersHelper.InstantiateProviders(docsection.Providers, _providers, typeof(DocumentProvider));
                docProvider = (DocumentProvider)_providers[docsection.DefaultProvider];
            }
            catch { }
        }
    }
}
